home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1994 August / August CD.bin / Shareware / Education / numericalmethods Folder / chap_4 / pade.m < prev    next >
Encoding:
Text File  |  1994-06-05  |  786 b   |  33 lines  |  [MATF/MATL]

  1. function [P,Q] = pade(C,n,m)
  2. % [P,Q] = pade(C,n,m)
  3. % The coefficient lists for Pn(x) and Qm(x) are computed.
  4. % Some combinations of n and m are incompatible.
  5. % C  is the list of Maclaurin coefficients, input.
  6. % n  is the degree of Pn(x), input.
  7. % m  is the degree of Qm(x), input.
  8. % P  is the coefficient list for Pn(x), output.
  9. % Q  is the coefficient list for Qm(x), output.
  10. C = flipud(C);
  11. A = C(1:n+m+1);
  12. % First solve an  m x m  system for the Q's
  13. Mq = zeros(m,m);
  14. for j = 1:m,
  15.   for k = 1:m,
  16.     Mq(j,k) = C(j+k);
  17.   end
  18. end
  19. for j = 1:m,
  20.   B(j) = - C(n+j+1);
  21. end
  22. if m > 0, Q = Mq\B'; end
  23. Q = [Q;1]';
  24. % Second solve an  n+1 x n+1  system for the P's.
  25. for j=1:n+1,
  26.   P(j) = A(j);
  27.   kmin = max(1,j-m);
  28.   for k=j-1:-1:kmin,
  29.     P(j) = P(j) + Q(m-(j-k)+1)*A(k);
  30.   end
  31. end
  32. P = fliplr(P);
  33.